package top.gcl.config;

import org.springframework.stereotype.Component;
import top.gcl.dao.GoodsMapper;
import top.gcl.entity.Goods;
import top.gcl.redis.RedisUtil;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.List;

@Component
public class GoodsLike {
    @Resource
    private GoodsMapper mapper;
    @Resource
   private  RedisUtil redisUtil;
    /**
     *点赞 先查询数据库中所有数据，然后把like数据和key放到redis中。
     */
    @PostConstruct
    public void handle()
    {
        List<Goods> lists=mapper.list();
        for(Goods goods:lists)
        {
            String id =goods.getId();
            int like=goods.getLikeNum();
            String redisKeyGoodLike="goods_like_"+id;
            redisUtil.set(redisKeyGoodLike,like);
        }
    }

}
